package com.zzyl.controller;

import com.zzyl.base.PageResponse;
import com.zzyl.base.ResponseResult;
import com.zzyl.dto.NursingProjectDTO;
import com.zzyl.entity.NursingProject;
import com.zzyl.service.NursingProjectService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import static com.zzyl.base.ResponseResult.success;

/**
 * 护理模块
 */
@Api(tags = "护理模块")
@RestController
@RequestMapping("/nursing_project")
public class NursingProjectController {

    @Autowired
    private NursingProjectService nursingService;

    /**
     * 分页查询
     * @param name
     * @param pageNum
     * @param pageSize
     * @param status
     * @return
     */
    @GetMapping
    @ApiOperation("分页查询")
    public ResponseResult paginatedQueries(String name,
                                           @RequestParam(defaultValue = "1")Integer pageNum,
                                           @RequestParam(defaultValue = "5")Integer pageSize,
                                           Integer status) {
        PageResponse pageResponse = nursingService.selectByPage(name, pageNum, pageSize, status);

        return success(pageResponse);
    }

    /**
     * 新增护理
     * @param nursingProjectDTO
     * @return
     */
    @PostMapping
    public ResponseResult add(@RequestBody NursingProjectDTO nursingProjectDTO){
        nursingService.add(nursingProjectDTO);
        return success();
    }

    /**
     * 根据id查询护理
     * @param id
     * @return
     */
    @GetMapping("/{id}")
    public ResponseResult<NursingProject> getByIdWithNursing(@PathVariable Integer id){
        return success(nursingService.getByIdWithNursing(id));
    }

    /**
     * 修改护理
     * @param nursingProjectDTO
     * @return
     */
    @PutMapping
    public ResponseResult updateNursing(@RequestBody NursingProjectDTO nursingProjectDTO){
        nursingService.updateNursing(nursingProjectDTO);
        return success();
    }

    /**
     * 更改护理状态
     * @param id
     * @param status
     * @return
     */
    @PutMapping("/{id}/status/{status}")
    public ResponseResult changeStatusById(@PathVariable Integer id,
                                       @PathVariable Integer status){
        nursingService.changeStatusById(id,status);
        return success();
    }

    /**
     * 删除护理
     * @param id
     * @return
     */
    @DeleteMapping("/{id}")
    public ResponseResult deleteById(@PathVariable Integer id){
        nursingService.deleteById(id);
        return success();
    }
}
